#ifndef     __OPENCVIF_H__
#define     __OPENCVIF_H__

#include "apptypedef.h"
#include "sysarch.h"
#include "OpencvIfEnums.h"
#include "hi_type.h"
#include "hi_common.h"
#include "hi_type.h"
#include "hi_comm_vb.h"
#include "hi_comm_sys.h"
#include "hi_comm_venc.h"
#include "hi_comm_vi.h"
#include "hi_comm_vo.h"
//#include "hi_comm_group.h"
#include "hi_comm_region.h"
#include "mpi_vb.h"
#include "mpi_sys.h"
#include "mpi_venc.h"
#include "mpi_vi.h"
#include "mpi_vo.h"
#include "mpi_region.h"
#include "sample_comm.h"

#include <linux/fb.h>
#include "hifb.h"
#include "loadbmp.h"


#include "hi_tde_api.h"
#include "hi_tde_type.h"
#include "hi_tde_errcode.h"

#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>

#include "mvMat.h"
#include "OpencvIfEnums.h"

using namespace cv;
using namespace std;

typedef struct
{
    char* pszName;          //接口名称

    HI_U32 u32Width;
    HI_U32 u32Height;

}TOpencvIfPara;


class COpencvIf
{
public:
	COpencvIf();
    virtual ~COpencvIf();

    bool initOpencvIf(TOpencvIfPara* pOpencvIfPara);

    int videoHiFrameToMat(VIDEO_FRAME_INFO_S *pVideoFrame, CmvMat *pView);
    int videoMatToHiFrame(CmvMat *pView, VIDEO_FRAME_INFO_S *pVideoFrame, VO_DEV VoDev, VO_CHN VoChn);
    int videoToHiFrame(VIDEO_FRAME_INFO_S *pstSrcVFrameInfo, VIDEO_FRAME_INFO_S *pstVFrameInfo, VO_DEV VoDev, VO_CHN VoChn);

    int createIplImage(IplImage &image, Size imageSize, char *pVirt);


    u32 getStride(u32 u32SrcPhyAddr, u32 u32Width, eOpencvIfStrideType eOpencvIfStride);
    int quickCopy(CmvMat *pMatSrc, CmvMat *pMatDst);
    int quickCopy(VIDEO_FRAME_INFO_S *pVideoFrame, CmvMat *pMatDst);
    int quickCopy(VIDEO_FRAME_INFO_S *pSrcFrame, VIDEO_FRAME_INFO_S *pDstFrame);

    int filter(CmvMat *pMatSrc, CmvMat *pMatDst, CmvMat as8Mask, u8 u8Norm);
    int filterVideoFrame(VIDEO_FRAME_INFO_S *pSrcVideo, VIDEO_FRAME_INFO_S *pDstVideo, CmvMat as8Mask, HI_U8 u8Norm);

    int colorConvertoBGR(VIDEO_FRAME_INFO_S *pSrcVideo, CmvMat *pMatDst);
    int filterCsctoBGR(VIDEO_FRAME_INFO_S *pSrcVideo, CmvMat *pMatDst, CmvMat as8Mask, u8 u8Norm);

    int canny(CmvMat *pMatSrc, CmvMat *pMatDst, CmvMat as8Mask);
    int dilate(CmvMat *pMatSrc, CmvMat *pMatDst, CmvMat au8Mask);
    int erode(CmvMat *pMatSrc, CmvMat *pMatDst, CmvMat au8Mask);
    int thresh(CmvMat *pMatSrc, CmvMat *pMatDst, u32 u32Thresh, u32 u32MinVal=0, u32 u32MaxVal=255);

    int andIamge(CmvMat *pMatSrc1, CmvMat *pMatSrc2, CmvMat *pMatDst);
    int subIamge(CmvMat *pMatSrc1, CmvMat *pMatSrc2, CmvMat *pMatDst);
    int orIamge(CmvMat *pMatSrc1, CmvMat *pMatSrc2, CmvMat *pMatDst);

    int integ(CmvMat *pMatSrc, CmvMat *pMatDst);
    int hist(CmvMat *pMatSrc, CmvMat *pMatDst);

protected:
    u32 m_VbPool;
    TOpencvIfPara* m_pOpencvIfPara;

    OS_SEM m_osSem;
};


#endif /* End of #ifndef __OPENCVIF_H__*/

